package cz.jj.tstr;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class RVAdapter extends RecyclerView.Adapter<RVAdapter.entryViewHolder>{

    ArrayList<monitorEntry.entry> entries ;
    public RVAdapter(monitorEntry mE){
        mE.generateEntryList();
        this.entries= mE.getEntries();

    }

    @NonNull
    @Override
    public entryViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
        entryViewHolder pvh = new entryViewHolder(v);
        return pvh;
    }

    @Override
    public void onBindViewHolder(@NonNull entryViewHolder holder, int position) {

        holder.stat_text.setText(entries.get(position).entryText);
        holder.state.setImageResource(entries.get(position).status_img);


    }

    @Override
    public int getItemCount() {
        return entries.size();
    }
    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
    }

    public static class entryViewHolder extends RecyclerView.ViewHolder {
        CardView cv;
        ImageView anchor;
        TextView stat_text;
        ImageView state;

        entryViewHolder(View itemView) {
            super(itemView);
            cv = (CardView)itemView.findViewById(R.id.crd_view);
            anchor = (ImageView) itemView.findViewById(R.id.left_anchor_img);
            stat_text = (TextView)itemView.findViewById(R.id.checkText);
            state = (ImageView)itemView.findViewById(R.id.state_but);
        }
    }

}